package com.eric.controller;

import cn.hutool.core.util.StrUtil;
import com.alibaba.fastjson.JSONObject;
import io.swagger.annotations.Api;
import lombok.SneakyThrows;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;

/**
 * @description: 京东银联请求控制器
 * @author: liuBing
 * @create: 2023-08-15 14:47
 **/
@Api("互联互通 银联控制器")
@RestController
@RequestMapping("inter/up")
public class InterUPController {


    @PostMapping("/component/register")
    @SneakyThrows
    public void componentRegister(@RequestParam("file") MultipartFile file, @RequestParam String imagePath) {

        StringBuilder content = new StringBuilder();

        try (InputStream inputStream = file.getInputStream();
             InputStreamReader inputStreamReader = new InputStreamReader(inputStream);
             BufferedReader reader = new BufferedReader(inputStreamReader)) {

            String line;
            while ((line = reader.readLine()) != null) {
                content.append(line);
            }
        }



        if (StrUtil.isNotBlank(content.toString())) {
            JSONObject param = JSONObject.parseObject(content.toString());
            param.put("image_url", imagePath);
            System.out.println(param);
        }

    }
}
